package com.tg.appcommon.android;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.view.View;

import androidx.annotation.ColorInt;
import androidx.annotation.LayoutRes;
import androidx.annotation.StringRes;

import com.module.appcommon.R;

public  class DialogUtil {
    public static void openGpsService(final Context context){
        new TGAlertDialog(context).builder().setTitle(R.string.open_gps_service).setMessage(R.string.open_gps_service_content)
                .setPositiveButton(R.string.permission_open, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    }
                }).show();
    }

    public static void openGpsService(final Context context, String title, String message){
        if (context != null){
            new TGAlertDialog(context).builder().setTitle(title).setMessage(message)
                    .setPositiveButton(R.string.permission_open, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            context.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                        }
                    }).setNegativeButton(R.string.permission_no_setting, new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            }).show();
        }
    }

    public static void openWifi(final Context context){
        if (context != null){
            new TGAlertDialog(context).builder().setTitle(R.string.dialog_notice).setMessage(R.string.open_wifi)
                    .setPositiveButton(R.string.permission_open, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                        }
                    }).show();
        }

    }
    public static void openPermissionForDeviceAdd(final Context context){
        openDlalog(context, R.string.permission_settings_location2,
                R.string.permission_device_add,
                R.string.permission_open,
                R.string.permission_no_setting,
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PermissionUtil permissionUtil = new PermissionUtil(context);
                        permissionUtil.openPermission();
                    }
                },
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    }
                });
    }
    public static void openPermissionForLogin(final Context context,View.OnClickListener setListener,View.OnClickListener cancleListener){
        openDlalog(context, R.string.permission_settings_location2,
                R.string.permission_device_login,
                R.string.permission_accept,
                R.string.permission_no_accept,
                setListener,
                cancleListener);
    }
    public static void openPermission(final Context context){
        openDlalog(context, R.string.permission_settings_location2,
                R.string.permission_electric_setting_tip,
                R.string.permission_open,
                R.string.permission_no_setting,
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        PermissionUtil permissionUtil = new PermissionUtil(context);
                        permissionUtil.openPermission();
                    }
                },
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    }
                });
    }

    public static void openDlalog(final Context context, String title, String message, String positiveBtn, String negativeBtn, final View.OnClickListener positiveBtnListener, final View.OnClickListener negativeBtnListener,  @ColorInt int color){
        if (context != null){
            new TGAlertDialog(context).builder().setTitle(title).setMessage(message).setPositiveButton(positiveBtn, positiveBtnListener).setNegativeButton(negativeBtn,negativeBtnListener).show(color);
        }
    }

    public static void openDlalog(final Context context, String title, String message, String positiveBtn, String negativeBtn, final View.OnClickListener positiveBtnListener, final View.OnClickListener negativeBtnListener){
        if (context != null){
            new TGAlertDialog(context).builder().setTitle(title).setMessage(message).setPositiveButton(positiveBtn, positiveBtnListener).setNegativeButton(negativeBtn,negativeBtnListener).show();
        }
    }


    public static void openDlalog(final Context context, @StringRes int title, @StringRes int message, @StringRes int positiveBtn, @StringRes int negativeBtn, final View.OnClickListener positiveBtnListener, final View.OnClickListener negativeBtnListener){
        if (context != null){
            new TGAlertDialog(context).builder().setTitle(title).setMessage(message)
                    .setPositiveButton(positiveBtn, positiveBtnListener).setNegativeButton(negativeBtn,negativeBtnListener).show();
        }
    }

    public static void openLockBellDialog(final Context context, @LayoutRes int resource, @StringRes int message, @StringRes int positiveBtn, @StringRes int negativeBtn, final View.OnClickListener positiveBtnListener, final View.OnClickListener negativeBtnListener){
        if (context != null){
            new TGAlertDialog(context).builder(resource).setTitle(0).setMessage(message)
                    .setPositiveButton(positiveBtn, positiveBtnListener).setNegativeButton(negativeBtn,negativeBtnListener).show();
        }
    }

}
